/*
 * Shiner - an abortion of a GUI element that looks shiny (optionally)
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#if flash9
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.GlowFilter;
import flash.filters.BitmapFilterQuality;
import flash.geom.Point;
import flash.Lib;
import flash3f.InputHandler;

class Shiner extends Bitmap
{

	public static var shiners : Array<Shiner> = new Array();

	public var original : BitmapData;
	public var glow : BitmapData;
	
	public function new(original : BitmapData, ?glow : GlowFilter)
	{
		super();
		this.original = original;
		var filter : GlowFilter;
		if (glow==null)
			filter = new GlowFilter(0x00FF00,0.8,4,4,2,BitmapFilterQuality.HIGH,true,false);
		else
			filter = glow;
		this.glow = new BitmapData(original.width, original.height);
		this.glow.applyFilter(original,original.rect,new Point(0,0),filter);
		this.bitmapData = original;

		Lib.current.addChild(this);
		shiners.push(this);
	}

	public static function clear()
	{
		for (n in shiners)
		{
			try
			{
				Lib.current.removeChild(n);
			}
			catch(foo : Dynamic) {}
		}
		shiners = new Array();
	}
	
	public static function up()
	{

		for (n in shiners)
		{

				if (n.bitmapData.rect.contains
				(InputHandler.cursx-n.x,InputHandler.cursy-n.y))
				{
					n.bitmapData = n.glow;
				}
				else
				{
					n.bitmapData = n.original;
				}
		}
	
	}


}
#else neko

class Shiner
{
	public static function up()
	{

	}
}
#end
